package com.qf.hello.spring.life;

import com.qf.hello.spring.service.UserService;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class MyPostProcessor implements BeanPostProcessor {

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        //默认是所有的bean在初始化之前都可以执行这里的代码
        System.out.println("初始化之前的生命周期");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        //默认是所有的bean在初始化之前都可以执行这里的代码
        if (bean instanceof UserService){
            // 加这个判断，可以只让UserService类型的bean初始化之后，执行这里代码
            System.out.println("初始化之后的生命周期");
        }
        return bean;
    }
}
